package org.andes.sgg;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import org.andes.base.Bindings;
import org.andes.kownledge.operator.Term;
import org.armedbear.lisp.LispObject;

public class st {
	//; ======================= st ====================================
	//; The st (short for state) struct represents a problem solver's
	//; state.  The working memory (wm) is the set of facts (ground atomic
	//; propositions) that the solver believes at this time.  The stack is
	//; an ordered list of operator instances, except for the top item on
	//; the stack, which might be a goal or an executable form instead of
	//; an operator instance.  The stuff in the stack has lots of
	//; variables in it.  Rather than continually substituting values
	//; into the variable, the state keeps a list of bindings (the format
	//; is defined by unifier.cl) which indicate what values all the
	//; variables appearing in the stack have. The history slot is a list
	//; of operator instance identifiers, which should all have their
	//; variables bound.  It is used to prevent the same operator from
	//; being executed twice in the same state.  The action slot is not
	//; used by the interpreter.  It is kept for building the solution
	//; graph later.  Similarly, the precedessor slot, which points to the
	//; preceding state, is only used for building the solution graph.

//	(defstruct (st (:print-function print-st))
//	  level          ; The level in search tree (for debugging)
//	  branches       ; T if multiple fellow branches in search tree (for debugging)
//	  bindings       ; A binding list (format defined by unifier.cl)
//	  wm	         ; A set of ground atomic propositions
//	  stack		 ; a list of operator instances (mostly)
//	  history	 ; a list of operator instance identifiers
//	  predecessor    ; the preceding state (represented as a st struct)
//	  actions	 ; list of s-expression recording the actions taken here
//	  )
	
	private boolean branches;
	private Bindings bindings=new Bindings();
	private List<Term> wm=new ArrayList<Term>();
	private Stack stack=new Stack();
	private List<Term> history=new ArrayList<Term>();
	private st predecessor;
	private List actions=new ArrayList();
	
	
	private int level;
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public boolean isBranches() {
		return branches;
	}
	public void setBranches(boolean branches) {
		this.branches = branches;
	}
	public Bindings getBindings() {
		return bindings;
	}
	public void setBindings(Bindings bindings) {
		this.bindings = bindings;
	}
	public void addAllBindings(Bindings bindings) {
		if(bindings==null)
			System.out.println("debug xxxx");
		else
			this.bindings.addAllBindings(bindings.getAllBindings());
	}
	
	public List<Term> getWm() {
		return wm;
	}
	public void addWme(Term lo) {
		this.wm.add(lo);
	}
	public void addWm(List<Term> lo) {
		this.wm.addAll(lo);
	}
	public Stack getStack() {
		return stack;
	}
	public void setStack(Stack stack) {
		this.stack = stack;
	}
	public void addAllStack(Stack stack1) {
		this.stack.addAll(stack1);
	}
	public List<Term> getHistory() {
		return history;
	}
	public void setHistory(List history) {
		this.history = history;
	}
	public void addAllHistory(List history) {
		this.history.addAll(history);
	}
	public st getPredecessor() {
		return predecessor;
	}
	public void setPredecessor(st predecessor) {
		this.predecessor = predecessor;
	}
	public List getActions() {
		return actions;
	}
	public void setActions(List actions) {
		this.actions = actions;
	}
	public void addAllActions(List actions){
		this.actions.addAll(actions);
		
	}
	public st copy(){
		st result=new st();
		result.addAllActions(this.getActions());
		result.addAllBindings(this.getBindings());
		result.addAllHistory(this.getHistory());
		result.addWm(getWm());
		result.addAllStack(this.getStack());
		
		return result;
	}
//	;;; The action list for the resulting state consists of <subacts> 
//	;;; for each substate.  Here <subacts> is a list
//	;;; of all the actions taken to achive the substate, with the oldest
//	;;; action first.  However, if none of the substates have any actions,
//	;;; then the action list is empty.
//
//	;; version without split and join and all that
//	(defun setof-actions (state initial-state)
//	  "Collects actions from the substates and puts them on the state"
//	  (setf (st-predecessor initial-state) NIL) ;halts actions-along-path
//	  (dolist (SubState (solution-sts initial-state))
//	    (setf (st-actions state)
//		  (append (actions-along-path SubState)
//			  (st-actions state)))))
	public void setofAction(st sub){
		
	}
	

}
